Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 3 - Values / Value Class Definitions


Styled Text

The class identifier Styled Text is a synonym for a string that includes style and font information.

LITERAL EXPRESSIONS
The only difference between a value of class String and a value of class Styled Text is that the latter can include (but is not required to include) style and font information. Thus any valid literal expression of class String is also valid as class Styled Text.

PROPERTIES
Class
The class identifier for the object. This property is read-only, and its value is always string.
Length
The number of characters in the string.
ELEMENTS
Styled text has the same character, word, paragraph, and text elements as
a string.

OPERATORS
Because values identified as Styled Text values are really values of class String, the operators available are the operators described in the definition of class String: &, =, , >, , <,, Starts With, Ends With, Contains, Is Contained By,
and As.

For detailed explanations and examples of how AppleScript operators treat strings, see "Operators That Handle Operands of Various Classes," which begins on page 168.

REFERENCE FORMS
You can use the same reference forms with styled text that you can use with strings: Property, Index, Middle, Arbitrary, Every Element, and Range. For details, see page 61.

SPECIAL CHARACTERS AND STRING CONSTANTS
You can use the same special characters, constants, and coercions with styled text that you can use with strings. For details, see page 61. Note that literal string constants do not include style and font information; in other words, they are not styled text.

COERCIONS SUPPORTED
You can use the same coercions with styled text that you can use with strings: coercion to an integer, number, real number, or single-item list, and coercion of a list of strings to a single concatenated string.

You can use the class identifier Styled Text to coerce any string to styled text. However, the resulting value is always of class String.

NOTES
You can't change the style or font information from a script, but you can use styled text to preserve style and font information when copying text objects from applications to scripts. For example, you can use a script like this to obtain styled text, manipulate it, and copy it back into a Scriptable Text Editor document:

tell application "Scriptable Text Editor"   copy (word 1 of front document) to myStyledTitle
   set myModifiedTitle to myStyledTitle & ", alpha release"   copy myModifiedTitle to word 1 of front document
end tell
Because the Scriptable Text Editor returns styled text when it returns the data for text objects, you don't need to coerce the returned text to styled text. The style and font of the first word are preserved both when the word is copied to the variable myStyledTitle and when it is concatenated with the string
", alpha release". The modified title that is copied back to the document consists of the original title with its original style and font, plus the unstyled text, ", alpha release", which appears in the style and font of the character immediately preceding it.

Styled text also contains information about the form in which the text is written. If you copy non-Roman text to a variable in a script as styled text, AppleScript preserves the original text information even though the
Script Editor may not be able to display it correctly. If you then copy the text
to an application that can handle the text in its original form, the text is
displayed correctly.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996